package com.ejia.dao;

import java.sql.*;

public class BaseDao {
	
	private static PreparedStatement ps;
	private static ResultSet rs;
	private static Connection conn;
	
	public static boolean execute(String sql,Object...objects) {
		conn=DBconnection.getconn();
		if (objects!=null) {
			try {
				ps=conn.prepareStatement(sql);
				for(int i=0;i<objects.length;i++) {
					ps.setObject(i+1, objects[i]);
				}
				int rs=ps.executeUpdate();
				return rs>0;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
				DBconnection.close(conn, ps, rs);
			}
		}
		return false;
	}
	
	
	public static ResultSet query(String sql,Object...objects) {
		conn=DBconnection.getconn();
		if (objects!=null) {
			try {
				ps=conn.prepareStatement(sql);
				for(int i=0;i<objects.length;i++) {
					ps.setObject(i+1, objects[i]);
				}
				rs=ps.executeQuery();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return rs;
	}
}
